using System;
using System.Collections.Generic;
using System.Text;
using Immersion.VO;
using System.Xml;

namespace Immersion.Dados
{
    public class dadosConfiguracao
    {
        public VOConfiguracao consultarConfiguracao()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("xml\\immersion_conf_structure.xml");

            VO.VOConfiguracao vo = null;
            vo = new VOConfiguracao();
            XmlNode elemento;

            elemento = doc.SelectSingleNode("/IMMERSION/CONFIGURATION/TIMECONF/FREQUENCY");
            vo.frequencia = elemento.InnerText;

            elemento = doc.SelectSingleNode("/IMMERSION/CONFIGURATION/TIMECONF/CONTINUO");
            vo.continuo = Convert.ToBoolean(elemento.InnerText);

            elemento = doc.SelectSingleNode("/IMMERSION/CONFIGURATION/LEVELCONF/LEVEL");
            vo.nivel = elemento.InnerText;

            //alimentando categoria informatica
            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT1/selected");
            vo.catInformatica = Convert.ToBoolean(elemento.InnerText);

            //alimentando categoria objetos
            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT2/selected");
            vo.catObjetos = Convert.ToBoolean(elemento.InnerText);

            //alimentando categoria outros
            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT3/selected");
            vo.catOutros = Convert.ToBoolean(elemento.InnerText);

            return vo;
        }

        public void salvarConfiguracoes(VOConfiguracao vo)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("xml\\immersion_conf_structure.xml");

            XmlNode elemento;
            elemento = doc.SelectSingleNode("/IMMERSION/CONFIGURATION/TIMECONF");
            elemento.SelectSingleNode("./FREQUENCY").InnerText = vo.frequencia;
            elemento.SelectSingleNode("./CONTINUO").InnerText = vo.continuo.ToString();
            doc.Save("xml\\immersion_conf_structure.xml");

            elemento = doc.SelectSingleNode("/IMMERSION/CONFIGURATION/LEVELCONF");
            elemento.SelectSingleNode("./LEVEL").InnerText = vo.nivel;
            doc.Save("xml\\immersion_conf_structure.xml");

            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT1");
            elemento.SelectSingleNode("./selected").InnerText = vo.catInformatica.ToString();
            doc.Save("xml\\immersion_conf_structure.xml");

            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT2");
            elemento.SelectSingleNode("./selected").InnerText = vo.catObjetos.ToString();
            doc.Save("xml\\immersion_conf_structure.xml");

            elemento = doc.SelectSingleNode("/IMMERSION/CATEGORIES/CAT3");
            elemento.SelectSingleNode("./selected").InnerText = vo.catOutros.ToString();
            doc.Save("xml\\immersion_conf_structure.xml");
        }
    }
}
